package com.aishua.aishuawallet.diydialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aishua.aishuawallet.R;

import java.util.List;


/**
 * Created by aishua on 2017/2/17.
 */

public class xLoadingDialog extends DialogFragment {


    public static xLoadingDialog newInstance(String msg) {

        xLoadingDialog dialog = new xLoadingDialog();
        Bundle args = new Bundle();
        args.putString("msg", msg);
        dialog.setArguments(args);
        return dialog;
    }

    @Override
    public void onStart() {
        super.onStart();
// TODO Auto-generated method stub
        super.onStart();

        Window window = getDialog().getWindow();
        WindowManager.LayoutParams windowParams = window.getAttributes();
        windowParams.dimAmount = 0.0f;

        window.setAttributes(windowParams);

    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        String msg = getArguments().getString("msg");

        LayoutInflater inflaterDl = LayoutInflater.from(getActivity());
        LinearLayout layout = (LinearLayout) inflaterDl.inflate(R.layout.xloding_dialog, null);

        //对话框
        final Dialog dialog = new Dialog(getActivity(), R.style.common_dialog_style);
        dialog.setContentView(layout);
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();

        dialogWindow.setGravity(Gravity.CENTER);
        lp.width = LinearLayout.LayoutParams.WRAP_CONTENT;  // 宽度

        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT; // 高度
        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);


        TextView tv_loading = layout.findViewById(R.id.tv_loading);
        tv_loading.setText(msg);


        return dialog;

    }

}
